#pragma once
#include<vector>

class Crossroad;
//关于时间的处理
class Time;
class Period;

class Crossroad;
class Dot;
//声明友元函数而文件无法互相包含，故在此声明类

class Time {        //时间
public:int hour;
	   int minute;
	   int second;
	   int layer;   //时间进位层数，比如0表示当天，1表示次日，以此类推，指针对于一个时段的起始时间的相对进位并非绝对进位
      Time(int a, int b, int c) :hour(a), minute(b), second(c), layer(0) { };
	  Time() :hour(0), minute(0), second(0), layer(0) {};
	  void Setlayer(int x) {        //设置时间进位
		  layer = x;
	  }
	  int Gethour() { return hour; }
	  int Getminute() { return minute; }
	  int Getsecond() { return second; }
	  friend class Period;
	  friend bool operator>(Time a, Time b);
	  friend bool operator<(Time a, Time b);
	  friend bool operator==(Time a, Time b);
	  friend bool operator>= (Time a, Time b);
	  friend bool operator<= (Time a, Time b);
	  friend bool isinPeriod(Time t, Period s);
	  friend Time operator+ (Time a, Period b);
	  friend Time operator+ (Time a, Time b);
	  friend Time operator- (Time a, Time b);
	  friend void SetCrossroadPassingTime(Crossroad& cro, Time Start, Time GreenDuration);
	  friend Time operator% (Time a, Time b);
};



class Period {    //时段
private:Time begin;   //起始时间
	   Time end;      //终止时间
	   Time duration;    //时长,以X时X分X秒的形式表示
	   int nextlayer;    //表示终止时间进位层数，0表示当天，1表示次日，以此类推
public:   Period(Time a, Time b) :begin(a), end(b) {
	nextlayer = end.layer;
	int s = this->end.second - this->begin.second;
	int m = this->end.minute - this->begin.minute;
	int h = (this->end.hour + 24 * this->nextlayer) - this->begin.hour;
	if (s < 0) {
		m -= 1;
		s += 60;
	}
	if (m < 0) {
		h -= 1;
		m += 60;
	}
	int day = 0;
	while (h >= 24) {
		h -= 24;
		day++;
	}
	Time* p = new Time(h, m, s);
	p->Setlayer(day);
	this->duration = *p;
}
	  friend bool isinPeriod(Time t, Period s);
	  friend Time operator+ (Time a, Period b);
	  friend void PassingCrossroad(Time& t, Crossroad& cro, int quadrant);
	  friend void PassingCrossroad(Time& t, Dot* cro, int quadrant);
};

const double WalkingVelocity = 0.2;   //步行速度，1个坐标单位相当于7.5米，按步行速度1.5m/s计算
const double CyclingVelocity = 2;     //骑行速度，按共享电动车骑行速度15m/s计算
const double BusVelocity = 4;     //校车速度，按校车速度30m/s计算